package com.njtoyo.taxi.admin.rest.controller.open;

import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.rest.wrapper.data.funnel.FunnelWrapper;
import com.njtoyo.taxi.admin.service.open.OpenFunnelService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("/open/funnel")
public class OpenFunnelController {


    @Autowired
    OpenFunnelService openFunnelService;


    /**
     * 统计
     *
     * @param params
     * @return
     */
    @GetMapping("/getCountToDayRide")
    @PassToken
    public RestResult<?> getCountToDayRide(@RequestParam Map<String, Object> params) {
        return openFunnelService.getCountToDayRide(params);
    }


    /**
     * 每小时完成订单数
     *
     * @return
     */
    @GetMapping("/getFinishOrderByHour")
    @PassToken
    public RestResult getFinishOrderByHour(@RequestParam Map<String, Object> params) {
        return openFunnelService.getFinishOrderByHour(params);
    }


    /**
     * 当月每天完单量
     *
     * @return
     */
    @GetMapping("/getFinishOrderByDay")
    @PassToken
    public RestResult getFinishOrderByDay(@RequestParam Map<String, Object> params) {
        return openFunnelService.getFinishOrderByDay(params);
    }


    /**
     * 最近30天每天的呼叫数据
     *
     * @return
     */
    @GetMapping("/get30DayCalls")
    @PassToken
    public RestResult get30DayCalls(@RequestParam Map<String, Object> params) {
        return openFunnelService.get30DayCalls(params);
    }


    /**
     * 每日司机抢单变化
     *
     * @return
     */
    @GetMapping("/get30DayGrapNum")
    @PassToken
    public RestResult get30DayGrapNum(@RequestParam Map<String, Object> params) {
        return openFunnelService.get30DayGrapNum(params);
    }


    /**
     * 近30天每日重复呼叫数
     *
     * @return
     */
    @GetMapping("/get30DayRepeatCallNum")
    @PassToken
    public RestResult get30DayRepeatCallNum(@RequestParam Map<String, Object> params) {
        return openFunnelService.get30DayRepeatCallNum(params);
    }


    /**
     * 每小时发单变化
     *
     * @return
     */
    @GetMapping("/sendByHour")
    @PassToken
    public RestResult sendByHour(@RequestParam Map<String, Object> params) {
        return openFunnelService.sendByHour(params);
    }


    /**
     * 每小时抢单变化
     *
     * @return
     */
    @GetMapping("/grabByHour")
    @PassToken
    public RestResult grabByHour(@RequestParam Map<String, Object> params) {
        return openFunnelService.grabByHour(params);
    }


    @GetMapping("/getTodayRide")
    @PassToken
    public RestResult getTodayRide(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                   @RequestParam(value = "size", required = false, defaultValue = "10") Integer size,
                                   @RequestParam(value = "cantonId", required = false, defaultValue = "7") Integer cantonId,
                                   @RequestParam(value = "type", required = false, defaultValue = "real_time") String type,
                                   @RequestParam(value = "date", required = false) String date) {

        return openFunnelService.getTodayRide(current, size, cantonId, type,date);
    }

    @GetMapping("/exportTodayRide")
    @PassToken
    public RestResult exportTodayRide(@RequestParam(value = "cantonId", required = false, defaultValue = "7") Integer cantonId,
                                      @RequestParam(value = "type", required = false, defaultValue = "real_time") String type,
                                      @RequestParam(value = "date", required = false) String date,
                                      HttpServletResponse response) {
        return openFunnelService.exportTodayRide(cantonId, type, date, response);
    }


    /**
     * 参与行程订单抢单的司机
     *
     * @return
     */
    @GetMapping("/rideJoinDriver")
    @PassToken
    public RestResult rideJoinDriver(@RequestParam Map<String, Object> params) {
        return openFunnelService.rideJoinDriver(params);
    }


    /**
     * 行程取消分析
     *
     * @return
     */
    @GetMapping("/getCancelAnalyse")
    @PassToken
    public RestResult getCancelAnalyse(@RequestParam Map<String, Object> params) {
        return openFunnelService.getCancelAnalyse(params);
    }


    /**
     * 呼叫单取消统计
     *
     * @param params
     * @return
     */
    @GetMapping("/getCallCancelAnalyse")
    @PassToken
    public RestResult getCallCancelAnalyse(@RequestParam Map<String, Object> params) {
        return openFunnelService.getCallCancelAnalyse(params);
    }


    @GetMapping("/cancel/list")
    @PassToken
    public RestResult getCancelList(@RequestParam Map<String, Object> params) {
        return openFunnelService.getCancelList(params);
    }


    /**
     * 每小时接单率、完单率变化
     *
     * @return
     */
    @GetMapping("/receiveAndFinishByHour")
    @PassToken
    public RestResult receiveAndFinishByHour(@RequestParam Map<String, Object> params) {
        return openFunnelService.receiveAndFinishByHour(params);
    }


    @GetMapping("/getScanRide")
    @PassToken
    public RestResult getScanRide(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                  @RequestParam(value = "size", required = false, defaultValue = "10") Integer size,
                                  @RequestParam(value = "cantonId", required = false, defaultValue = "7") Integer cantonId,
                                  @RequestParam(value = "type", required = false, defaultValue = "real_time") String type,
                                  @RequestParam(value = "startDate", required = false) String startDate,
                                  @RequestParam(value = "endDate", required = false) String endDate) {

        return openFunnelService.getScanRide(current, size, cantonId, type, startDate, endDate);
    }


    @PostMapping("/saveActivityReward")
    @PassToken
    public RestResult saveActivityReward(@RequestParam Map<String, Object> params) {
        return openFunnelService.saveActivityReward(params);
    }


    @GetMapping("/exportActivityReward")
    @PassToken
    public void exportActivityReward(@RequestParam(value = "startDate", required = false) String startDate,
                                     @RequestParam(value = "endDate", required = false) String endDate,
                                     HttpServletResponse response) {
        openFunnelService.exportActivityReward(startDate, endDate, response);
    }

}
